package com.synjones.aamodule;

/**
 * 指纹模块控制
 * @ClassName AAModuleControl
 * @author zhaodianbo@Synjones
 * @date 2015-10-10 下午4:56:16
 *
 */
public class AAModuleControl {
	static
	{
		System.loadLibrary("aa");
	}

	public static final int MSG_SUCCESS		=	0;
	public static final int MSG_FAILURE		=	1;
	public static final int MSG_INVALID_VALUE=	2;
	public static final int MSG_ERROR		=	4;
	public static final int MSG_ENROLL_START=	5;
	public static final int MSG_VERIFY_START=	6;
	public static final int MSG_BADIMAGE	=	7;
	public static final int MSG_MOREIMAGE   =    8;
	public static final int MSG_NOTEXIST	=	9;
	public static final int MSG_CAPTUREIMAGE=	10;
	public static final int MSG_DETECTIMAGE	=	12;
	public static final int MSG_SENSOR_FAILURE=	11;
	public static final int MSG_MEMORY_ERROR=	20;
	public static final int RET_NO_CONNECTION = -100;
	public static final int RET_IMAGE_ERROR =   -101;
	public static final int RET_TIMEOUT		=   -102;
	public static final int MSG_QUERYCONTINUE   =    255;
	//HandsetDriver hd;
	AAModuleCallbackInterface callBackFunc;

	public AAModuleControl(AAModuleCallbackInterface callBackFunc){
		this.callBackFunc=callBackFunc;
		//hd=HandsetDriver.getHandsetDriver();
	}

	public void powerOn(){
		//hd.Power_OFF();
		//hd.FingerprintModule_ON();
		//hd.switchPort(HandsetDriver.FPModule_PORT);
	}
	public void powerOff(){
		/*try {
			hd.FingerprintModule_OFF();
		} catch (Exception e) {}*/
	}


	//libaa.so会调用此函数，函数名不可更改
	public void processImage(byte[] buffer,int width,int height){
		callBackFunc.processImage(buffer, width, height);
	}

	//libaa.so会调用此函数，函数名不可更改
	public int AAModuleMsgCallback(int msg, int param){
		return callBackFunc.AAModuleMsgCallback(msg, param);
	}
	/**
	 * 打开模块，设定安全等级
	 * @Title AAModuleOpen
	 * @param securityLevel
	 * @return
	 */
	public native int AAModuleOpen(int securityLevel,String path);
	public native int AAModuleClose();

	/**
	 * 下载指纹特征模板
	 * @Title AAModuleSetTemplate_2ndID
	 * @param id 索引
	 * @param data 特征值
	 * @param size 大小=512
	 * @param cFlag 旋转标志
	 * @return
	 */
	public native int AAModuleSetTemplate_2ndID(int id, byte data[] , int size, int cFlag);
	/**
	 * 指纹对比
	 * @Title AAModuleVerify
	 * @param id 0全对比 >0对比指定的ID
	 * @param image_download 是否显示图像
	 * @return >=0 :  比对完成。返回值 ret 的低 8 位（ret&0xFF）为比对的（最高）分数，高
	24 位（ret>>8）为得到该分数的特征数据的 id。
	 */
	public native int AAModuleVerify(int id, int image_download);
	/**
	 * 清除模块内的特征值
	 * @Title AAModuleClear
	 * @return
	 */
	public native int AAModuleClear();
	/**
	 * 录入指纹
	 * @Title AAModuleEnroll
	 * @param fp_template 返回的特征值 大小512字节
	 * @param image_download 是否显示图像
	 * @return
	 */
	public native int AAModuleEnroll( byte fp_template[], int image_download);
	/**
	 * 当芯片连接的采集仪采集的图像质量下降明显时校准传感器。
	 * @Title AAModuleCalibration
	 * @return
	 */
	public native int AAModuleCalibration();



	/**
	 * 设置注册指纹时扫描的次数
	 * @Title AAModuleSetEnrollImageCount
	 * @param count
	 * @return
	 */
	public native int AAModuleSetEnrollImageCount(int count);
}
